package com.itheima.book.interceptor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截器配置
 */
@Configuration
@Slf4j
public class interceptorconfig implements WebMvcConfigurer {
    /*@Autowired
    private JwtTokenAdminInterceptor jwtTokenAdminInterceptor;*/
    @Autowired
    private JwtTokenUserInterceptor jwtTokenUserInterceptor;

    /**
     * 注册自定义拦截器
     *
     * @param registry
     */
    public void addInterceptors(InterceptorRegistry registry) {
        log.info("开始注册自定义拦截器...");
        /*registry.addInterceptor(jwtTokenAdminInterceptor)
                .addPathPatterns("/admin/**")
                .excludePathPatterns("/admin/employee/login");*/

        registry.addInterceptor(jwtTokenUserInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(
                        "/api/login",
                        "/api/login/sms",
                        "/api/login/email",           // 登录接口
                        "/api/register",        // 注册接口
                        "/api/sms/sendcode",    // 短信验证码接口
                        "/api/sms/singup/sendcode",    // 短信验证码接口
                        "/api/email/code",    // 邮箱验证码接口
                        "/doc.html",            // swagger文档
                        "/swagger-ui.html",     // swagger文档UI
                        "/swagger-ui/**",       // swagger-ui相关资源
                        "/webjars/**",          // swagger资源
                        "/v3/**",               // openapi资源
                        "/swagger-resources/**", // swagger资源
                        "/v2/api-docs/**"       // swagger API文档
                );
    }
}
